package fr.cephb.servlet;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletOutputStream;

/** A class overriding ServletOutputStream to 
 * redirect the output of a servlet to a deledate ouput stream 
 */
public class DelegateServletOutputStream extends ServletOutputStream {
	private OutputStream delegate=null;
	
	/**
	 * Constructor
	 * @param delegate the delegate output stream where the 
	 * servlet should be redirected
	 */
	public DelegateServletOutputStream(OutputStream delegate)
		{
		this.delegate=delegate;
		}
	/**
	 * return the delegate output stream where the 
	 * servlet should be redirected
	 */
	private OutputStream getDelegate()
		{
		return this.delegate;
		}
	
	@Override
	public void write(int b) throws IOException
		{
		getDelegate().write(b);
		}

	public void close() throws IOException {
		getDelegate().close();
	}

	public void flush() throws IOException {
		getDelegate().flush();
	}

	public void print(boolean b) throws IOException {
		print(b ? "true" : "false");
	}

	public void print(char c) throws IOException {
		print(String.valueOf(c));
	}

	public void print(double d) throws IOException {
		print(String.valueOf(d));
	}

	public void print(float f) throws IOException {
		print(String.valueOf(f));
	}

	public void print(int i) throws IOException {
		print(String.valueOf(i));
	}

	public void print(long l) throws IOException {
		print(String.valueOf(l));
	}

	public void print(String s) throws IOException {
		for(int i=0;i< s.length();++i)
			{
			write(s.charAt(i));
			}
	}

	public void println() throws IOException {
		print('\n');
	}

	public void println(boolean b) throws IOException {
	   print(b); println();
	}

	public void println(char c) throws IOException {
		print(c); println();
	}

	public void println(double d) throws IOException {
		print(d); println();
	}

	public void println(float f) throws IOException {
		print(f); println();
	}

	public void println(int i) throws IOException {
		print(i); println();
	}

	public void println(long l) throws IOException {
		print(l); println();
	}

	public void println(String s) throws IOException {
		print(s); println();
	}

	public void write(byte[] b, int off, int len) throws IOException {
		getDelegate().write(b, off, len);
	}

	public void write(byte[] b) throws IOException {
		getDelegate().write(b);
	}

}
